

var app = angular.module('app', ['ngAnimate', 'mgcrea.ngStrap','mgcrea.ngStrap.select','ngSanitize','ngTouch', 'ui.grid']);
 
app.directive("myHerf",function(){
  return {
    restrict:'EA',
    replace:false,
    template: '<a herf="{{myProperty}}">Click Me</a>',
    scope:{
      //将指令的私有属性 $scope.myUrl 同DOM中 some-attr 属性的值绑定起来。
      myProperty:'@someAttr'
    }
  }
});

app.directive('myInput',function(){
  return {
    restrict:'EA',
    template:''
  }
});
    
app.controller('MainCtrl', ['$scope', '$http','$modal','$templateCache',function ($scope, $http,$modal,$templateCache) {


 $scope.selectedState = '';
  $scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];

  $scope.selectedIcon = '';
  $scope.icons = [
    {value: 'Gear', label: '<i class="glyphicon glyphicon-music"></i> Gear'},
    {value: 'Globe', label: '<i class="fa fa-globe"></i> Globe'},
    {value: 'Heart', label: '<i class="fa fa-heart"></i> Heart'},
    {value: 'Camera', label: '<i class="fa fa-camera"></i> Camera'},
    {value: 'Camera', label: '<i class="fa fa-camera"></i> Camera'},
    {value: 'Camera', label: '<i class="fa fa-camera"></i> Camera'},
    {value: 'Camera', label: '<i class="fa fa-camera"></i> Camera'},
    {value: 'Heart', label: '<i class="fa fa-heart"></i> Heart'},
    {value: 'Heart', label: '<i class="fa fa-heart"></i> Heart'},
    {value: 'Heart', label: '<i class="fa fa-heart"></i> Heart'},
    {value: 'Heart', label: '<i class="fa fa-heart"></i> Heart'}
  ];

  $scope.selectedAddress = '';
  $scope.getAddress = function(viewValue) {
    var params = {address: viewValue, sensor: false};
    return $http.get('http://maps.googleapis.com/maps/api/geocode/json', {params: params})
    .then(function(res) {
      return res.data.results;
    });
  };


  $scope.dataType =  [
  {name:"By Step Instruction"},
  {name:"By Agile Doc Number"},
  {name:"By Agile Part Number"},
  {name:"By Agile Deviation Number"},
  {name:"By Agile Deviation Date"},
  {name:"By Local Document"},
  {name:"By Local Deviation Number"},    
  {name:"Engineering Notes by Route Independent"},
  {name:"By Engineering Notes"},
  {name:"By URL"}
  ];
  $scope.selected = $scope.dataType[0].name;
  var pageSize = 8;
  $scope.gridOptions1 = {
    paginationPageSizes: [10, 15, 20],
    paginationPageSize: pageSize,
    columnDefs: [
      { name: 'PartFamily' ,width:90 ,field: 'partFamily' },
      { name: 'PartNumber',width:90,field: 'partKey' },
      { name: 'ProcessName' ,width:100,field: 'processName'},
      { name: 'Document',field: 'attaFileName' },
      { name: 'Type' ,field: 'contentType' },
      { name: 'Start Page',width:90,field: 'startPage' },
      { name: 'End Page' ,field: 'endPage'},
      { name: 'Revision',field: 'revision' },
      { name: 'Default' },
      { name: 'Convert' },
      { name: 'Assign',field: 'assignTo' },
      { name: 'Value' ,field: 'assignValue'},
      { name: 'Effective From',field: 'effectiveFrom' },
      { name: 'Effective To' ,field: 'effectiveTo'},
    ]
  };
 
  $scope.gridOptions2 = {
   paginationPageSizes: [10, 15, 20],
   paginationPageSize: pageSize,
   columnDefs: [
   { name: 'Document'  ,field: 'attaFileName' },
   { name: 'Revision',field: 'revision' },
   { name: 'Agile Document Number' ,field: 'docNumber'},
   { name: 'Description',field: 'title' }
   ]
  }
  $http({
	  method: 'POST',
	  url: '../angularServlet',
      params:{
        pageSize:pageSize
      }
  }).success(function (data) {
    $scope.gridOptions2.data = data.list;
  });

  $http({
    method: 'POST',
    url: '../angularServlet',
      params:{
        pageSize:pageSize
      }
  }).success(function (data) {
    $scope.gridOptions1.data = data.list;
  });

  $scope.addAction = function(){
    $http({
        method: 'POST',
        url: '../angularServlet',
        params:{
          name:'Mercy'
        }}).success(function(data,status,headers,config) {
        // 
        }).error(function(data,status,headers,config) {
        // 当响应以错误状态返回时调用
        });
    }
$scope.modal = {
  "title": "Title",
  "link":"",
  "content": "Hello Modal<br />This is a multiline message!"
};



  // Pre-fetch an external template populated with a custom scope
  var myOtherModal = $modal({scope: $scope, templateUrl: 'modal.demo.tpl.html', show: false});
  // Show when some event occurs (use $promise property to ensure the template has been loaded)
  $scope.showModal = function() {
    myOtherModal.$promise.then(myOtherModal.show);
  };
}]);
/*!function(){
  var div  = document.createElement('div');
  div.className = "from-control";
  div.width = 16;
  div.height=34;
  var span = document.createElement('button');
  span.className="btn-default combobox-down glyphicon glyphicon-triangle-bottom";
  var combo = $('.combobox');
  combo.after(span);
  $('.combobox-down').click(function(event) {
    $(this).prev().focus();
  });
}();
*/
$(document).ready(function(){
    $('.combobox').combobox();
   // $('.textbox-addon-right').children("a")[0].className  = "textbox-icon combobox-down glyphicon glyphicon-triangle-bottom";
  });